// Created by Jisam on 2024/8/10 20:22.
// solve 线段和
#include <bits/stdc++.h>

#define endl "\n"
#define PSI pair<string,int>
#define PII pair<int,int>
#define PDI pair<double,int>
#define PDD pair<double,double>
#define VVI vector<vector<int>>
#define VI vector<int>
#define VS vector<string>

#define PQLI priority_queue<int, vector<int>, less<int>>
#define PQGI priority_queue<int, vector<int>, greater<int>>
using u32 = unsigned;
using i64 = long long;
using u64 = unsigned long long;

using namespace std;


// solve函数用于解决线段和问题
void solve() {
    int n;
    cin >> n;
    map<i64, int> mp;
    i64 l, r;
    for (int i = 0; i < n; i++) {
        cin >> l >> r;
        mp[l]++;
        mp[r + 1]--;
    }
    i64 ans = 0, lo = LONG_LONG_MAX, cur = 0;
    for (auto [rh, n]: mp) {
        cur += n;
        if (cur > 1) {
            lo = min(lo, rh);
        } else {
            ans = max(ans, rh - lo);
            lo = LONG_LONG_MAX;
        }
    }

    cout << ans << "\n";

}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    // 可以输入测试用例数量
//    cin >> T;
    while (T--) solve();
    // 分隔测试用例输出
//    cout << "\n";
    return 0;
}
